#include <math.h>
#include <stdio.h>

float sin_taylor (float x) {
	const float pi = 3.14159265359;

	float  k = floor( x / (2*pi) );		// k = parte entera de la division. Por suerte x nunca es negativo :P

	float r = x - (k * 2 * pi);

	x = r - pi;

	float y = x - (pow(x,3.0) / 6.0) + (pow(x,5.0) / 120.0) - (pow(x, 7.0) / 5040.0);

	return y;
}

float prof(int i, int j, float x_scale, float y_scale)
{
	float i_sin_taylor = sin_taylor(i / 8.0);
	float j_sin_taylor = sin_taylor(j / 8.0);

	float result = (x_scale * i_sin_taylor) + (y_scale * j_sin_taylor);
	result = result / 2;

	return result;
}

void waves_c (
	unsigned char *src,
	unsigned char *dst,
	int m,					// high
	int n,					// width
	int row_size,
	float x_scale,
	float y_scale,
	float g_scale
) {
	//unsigned char (*src_matrix)[row_size] = (unsigned char (*)[row_size]) src;
	//unsigned char (*dst_matrix)[row_size] = (unsigned char (*)[row_size]) dst;

	int posActual = 0;
	float valueActual = 0;
	for(int i=0; i<m; ++i)
		for (int j=0; j<n; ++j)
		{
			posActual = (i * row_size) + j; 
			valueActual = (prof(i, j, x_scale, y_scale) * g_scale) + (float) src[posActual];

			if (valueActual < 0.0)
				valueActual = 0.0;
			else if (valueActual > 255.0)
				valueActual = 255.0;
			dst[posActual] = (unsigned char) valueActual;
		}
}






